import {fileURLToPath, URL} from 'node:url';

import {defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import {VantResolver} from 'unplugin-vue-components/resolvers';
import compressPlugin from "vite-plugin-compression";
import cssPlugin from 'postcss-pxtorem'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0',
    port: 8866,
    proxy: {
      '/apis': {
        //target: 'http://192.168.2.19:8973',
         target: 'https://avm.aptoken.xyz',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/apis/, '')
      }
    }
  },
  base: './',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    }),
    compressPlugin(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    postcss: {
      plugins: [
        cssPlugin({
          rootValue: 37.5,
          unitPrecision: 5,
          propList: ['*'],
          replace: true,
          mediaQuery: false,
          minPixelValue: 0,
          exclude: /node_modules/i
        })
      ]
    },
  },
  build: {
    chunkSizeWarningLimit: 1000,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true
      }
    }
  }
});
